#ifndef CELL_H
#define CELL_H

#include <QLabel>

class Cell : public QLabel {
    Q_OBJECT
public:
    /* 未被点开时的状态，可以被玩家通过右键标记为Flaged或者Questioned */
    using CellState = enum {
        ORIGINAL = 0,
        FLAGED = 1,
        QUESTIONED = 2,
        HIGHLIGHTED = 3, /* 鼠标悬停效果 */
    };

    using CellOpenedByWho = enum {
        ME = 0,
        OPPONENT = 1,
        SYSTEM = 2,
    };

    Cell(QWidget *parent=nullptr);

    int showByCurrentState();

    /* 根据当前的状态展示不同的图片，当前配色方案： 己方点开的显示蓝色，对方点开的显示红色，系统点开的显示黄色 */
    void showImage();

    bool isBomb() const;
    void setIsBomb(bool newIsBomb);

    bool isOpened() const;
    void setIsOpened(bool newIsOpened);

    uint8_t openedByWho() const;
    void setOpenedByWho(uint8_t newOpenedByWho);

    uint8_t state() const;
    void setState(uint8_t newState);

    uint32_t bombsAround() const;
    void setBombsAround(uint32_t newBombsAround);

    void reset()
    {
        isBomb_ = false;
        isOpened_ = false;
        openedByWho_ = ME;
        state_ = ORIGINAL;
        bombsAround_ = 0;
    }

private:
    bool isBomb_ = false;       /* 是否是地雷 */
    bool isOpened_ = false;
    uint8_t openedByWho_ = ME;   /* 被谁打开 @ref CellOpenedByWho */
    uint8_t state_ = ORIGINAL;     /* @ref CellState */
    uint32_t bombsAround_ = 0;
    QPixmap image_;
};

#endif // CELL_H
